# Maintainer: Lubosz Sarnecki <lubosz@gmail.com>

_realname=gst-python
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
pkgver=1.6.2
pkgrel=1
pkgdesc="GStreamer GObject Introspection overrides for Python 3 (mingw-w64)"
arch=('any')
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gstreamer"
         "${MINGW_PACKAGE_PREFIX}-python3-gobject"
         "${MINGW_PACKAGE_PREFIX}-gobject-introspection")
makedepends=('git')
url='https://gstreamer.freedesktop.org/modules/gst-python.html'
options=(!libtool strip staticlibs)

source=(https://gstreamer.freedesktop.org/src/gst-python/${_realname}-${pkgver}.tar.xz
        '0001-msys2-python3-config-returns-1-so-use-which.patch'
        '0002-msys2-fix-linking-errors.patch'
        '0004-add-overrides.patch'
        '0005-unix-override-dir.patch')
sha256sums=('4e763e317079f48a2d6f37bd600bc19650d61597fac9f5763dbad293f72f9125'
            '836cf2e9e713705e5fd0f09d4e38d3de839a3c663eb6fa85f0a3f9a5f0b224ee'
            'dc4cd0f1890d82e5d09e667763b6a7c1731864e3ddfe4f0ff42d3e83de4def20'
            '04f94d86379280d6a4d7970dd149f31ef9ea04f5151dc6f9be474069570366ac'
            '00803a24df44a66e6116b1a01fa381903216a4409a4926e05b43a34dea224c08')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-msys2-python3-config-returns-1-so-use-which.patch
  patch -p1 -i ${srcdir}/0002-msys2-fix-linking-errors.patch
  patch -p1 -i ${srcdir}/0004-add-overrides.patch
  patch -p1 -i ${srcdir}/0005-unix-override-dir.patch

  WANT_AUTOMAKE=latest autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p build-${MINGW_CHOST}
  cd "${srcdir}/build-${MINGW_CHOST}"

  PYTHON=${MINGW_PREFIX}/bin/python3 \
  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --bindir=${MINGW_PREFIX}/bin \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --disable-silent-rules

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install

  mv ${pkgdir}${MINGW_PREFIX}/lib/bin/*.dll ${pkgdir}${MINGW_PREFIX}/lib/gstreamer-1.0/
  rm -rf ${pkgdir}${MINGW_PREFIX}/lib/bin
}
